package org.dei.perla.sys.query.llqruntime.datastructures;

import java.util.HashMap;

import org.dei.perla.parser.expressions.Constant;
import org.dei.perla.parser.expressions.ConstantTimestamp;
import org.dei.perla.parser.expressions.ConstantNull;

public class Record {
	
	private Constant pConstant[];
	private QueryRecordStructure pQueryRecordStructure;
	
	public Record (QueryRecordStructure parQueryRecordStructure){
		pConstant = new Constant[parQueryRecordStructure.getSize()];
		pQueryRecordStructure = parQueryRecordStructure;
	}
	
	
	public HashMap<String,QueryFieldStructure> getRecordStructure() {
		return this.pQueryRecordStructure.getRecordStructure();
	}
	
	public void setField (String parFieldName, Constant parField){
		pConstant[this.pQueryRecordStructure.getIndexByName(parFieldName)]= parField;
	}
	
	public Constant getField (String parFieldName){
		if (pConstant[this.pQueryRecordStructure.getIndexByName(parFieldName)] == null)
			return new ConstantNull();
		
		return pConstant[this.pQueryRecordStructure.getIndexByName(parFieldName)]; 
	}
	
	public Constant getField (int parFieldIndex){
		if (pConstant[parFieldIndex] == null)
			return new ConstantNull();
		return pConstant[parFieldIndex];
	}
	
	public ConstantTimestamp getTimestamp(){
		return (ConstantTimestamp)pConstant[this.pQueryRecordStructure.getIndexTimestamp()];
	}
	
	public String toString(){
		String tString = "";	
		
		for(int i=0; i<pConstant.length; i++ )
			tString = tString + pConstant[i].toString() + "\n";
		
		
		return tString;
	}
}
